package org.hgf.testrabbitmq.domain;

import lombok.Builder;
import org.hgf.testrabbitmq.utils.enums.ExchangeTypeEnum;

import java.io.Serializable;
import java.util.Collections;
import java.util.Map;

/**
 * 消息队列相关配置
 *
 * @author 何国发
 * @version 1.0.0
 * @date 2022/9/7 15:02
 */
@Builder
public class MqConfig implements Serializable {

    /**
     * 队列名称
     */
    private String queueName;

    /**
     * 交换机类型
     */
    private ExchangeTypeEnum exchangeTypeEnum;

    /**
     * 交换机名称
     */
    private String exchangeName;

    /**
     * 队列和交换机的绑定路由键
     */
    private String routeKey;

    /**
     * 绑定参数map
     */
    private Map<String, Object> paramMap;

    /**
     * 要传输的消息
     */
    private Object message;

    public String getQueueName() {
        return queueName;
    }

    public void setQueueName(String queueName) {
        this.queueName = queueName;
    }

    public ExchangeTypeEnum getExchangeTypeEnum() {
        if (exchangeTypeEnum == null || "".equals(exchangeName))
        {
            exchangeTypeEnum = ExchangeTypeEnum.FANOUT;
        }
        return exchangeTypeEnum;
    }

    public void setExchangeTypeEnum(ExchangeTypeEnum exchangeTypeEnum) {
        if (exchangeTypeEnum == null || "".equals(exchangeName))
        {
            exchangeTypeEnum = ExchangeTypeEnum.FANOUT;
        }
        this.exchangeTypeEnum = exchangeTypeEnum;
    }

    public String getExchangeName() {
        return exchangeName;
    }

    public void setExchangeName(String exchangeName) {
        this.exchangeName = exchangeName;
    }

    public String getRouteKey() {
        if (routeKey == null)
        {
            routeKey = "";
        }
        return routeKey;
    }

    public void setRouteKey(String routeKey) {
        if (routeKey == null)
        {
            routeKey = "";
        }
        this.routeKey = routeKey;
    }

    public Map<String, Object> getParamMap() {
        return paramMap;
    }

    public void setParamMap(Map<String, Object> paramMap) {
        this.paramMap = paramMap;
    }

    public Object getMessage() {
        return message;
    }

    public void setMessage(Object message) {
        this.message = message;
    }

    public MqConfig() {}

    public MqConfig(String queueName, String exchangeName, Object message)
    {
        this.queueName = queueName;
        this.exchangeTypeEnum = ExchangeTypeEnum.FANOUT;
        this.exchangeName = exchangeName;
        this.routeKey = "";
        this.paramMap = Collections.emptyMap();
        this.message = message;
    }

    public MqConfig(String queueName, ExchangeTypeEnum exchangeTypeEnum, String exchangeName, Object message)
    {
        this.queueName = queueName;
        this.exchangeTypeEnum = exchangeTypeEnum;
        this.exchangeName = exchangeName;
        this.routeKey = "";
        this.paramMap = Collections.emptyMap();
        this.message = message;
    }

    public MqConfig(String queueName, ExchangeTypeEnum exchangeTypeEnum, String exchangeName, String routeKey, Object message) {
        this.queueName = queueName;
        this.exchangeTypeEnum = exchangeTypeEnum;
        this.exchangeName = exchangeName;
        this.routeKey = routeKey;
        this.paramMap = Collections.emptyMap();
        this.message = message;
    }

    public MqConfig(String queueName, ExchangeTypeEnum exchangeTypeEnum, String exchangeName, String routeKey, Map<String, Object> paramMap, Object message) {
        this.queueName = queueName;
        this.exchangeTypeEnum = exchangeTypeEnum;
        this.exchangeName = exchangeName;
        this.routeKey = routeKey;
        this.paramMap = paramMap;
        this.message = message;
    }

}
